function TreeNode(val, left, right) {
  this.val = val == undefined ? 0 : val;
  this.left = left == undefined ? null : left;
  this.right = right == undefined ? null : right;
}

function createTree() {
  const root = new TreeNode(1);
  root.left = new TreeNode(2);
  root.left.left = new TreeNode(3);
  root.left.right = new TreeNode(4);
  root.right = new TreeNode(2);
  root.right.left = new TreeNode(4);
  root.right.right = new TreeNode(3);
  return root;
}

function printTree(root){
  if (root === null) return;
  console.log(root.val); // 访问当前节点
  printTree(root.left); // 递归遍历左子树
  printTree(root.right); // 递归遍历右子树
};

function isSymmetric(root) {
  if (root == null) return true;
  return isMirror(root.left, root.right)
}

function isMirror(left, right){
  if(left == null && right == null){
    return true
  }
  if((left == null && right != null) || (left != null && right == null)){
    return false
  }
  return (left.val == right.val && isMirror(left.left, right.right) && isMirror(left.right, right.left))
}

const root = createTree();
printTree(root)
console.log(isSymmetric(root))
